
import 'package:flutter/material.dart';
import 'package:myapp/page/messageTransfer/children.dart';

class Parent extends StatefulWidget {


  const Parent({ super.key });

  @override
  State<Parent> createState() => _Content();

}

class _Content extends State<Parent> {

  late String parentMessage = '';

  void _callChildMethod() {
    childKey.currentState?.addContent();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        const Text('parent'),
        SizedBox(
          width: double.infinity,
          child: ElevatedButton(
              onPressed: () {
                setState(() {
                  parentMessage = 'parentMessage!';
                });
              },
              child: const Text('增加')
          ),
        ),

        SizedBox(
          width: double.infinity,
          child: ElevatedButton(
              onPressed: _callChildMethod,
              child: const Text('父调用子方法')
          ),
        ),

        Children(parentMessage: parentMessage, key: childKey)
      ],
    );
  }

}